﻿using Assets.Script.Human.Player.Config;
using Newtonsoft.Json;
using SimpleTools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets.Script.HelpSystem.SaveSystem
{
    public class SaveManager
    {

        public static SaveData saveData;

        private static readonly string savePath="/Save/data.json";

        /// <summary>
        /// 游戏开始时初始化 读档
        /// </summary>
        /// <returns>是否创建了新存档</returns>
        public static bool  Read()
        {
            var s = FileHelp.GetStringData(Application.persistentDataPath + savePath);
            if (s!=null)
            {
                saveData = JsonConvert.DeserializeObject<SaveData>(s);
                return false;
            }
            else
            {
                saveData = new SaveData();
                saveData.CreateNewSave();
                return true;
            }
        }



        //存档
        public static void Save()
        {
            FileHelp.SaveStringData(Application.persistentDataPath + savePath, JsonConvert.SerializeObject(saveData));
            Debug.Log("保存");
        }
    }

    public class SaveData
    {
        //经济
        public int Coin;
        //进度
        public int CaseNum;
        //任务
//        public List<TaskInfo> TaskList;//任务组件
        //成就
//        public List<TaskInfo> AchList;//任务组件

        //统计组件
//        public StatisticsData StatisticsData;
        //多玩家组件
        public RolePool HeroConfig;
        public string HeroName;
        public void CreateNewSave()
        {
            //进度
            CaseNum = 1;
            //经济
            Coin = 0;
            //任务组件
//            TaskList = new List<TaskInfo>();
//            AchList = new AchPool().GetAchs();

 //           StatisticsData = new StatisticsData();

            HeroConfig = new RolePool();
            HeroConfig.Create();
            HeroName = "BallBoy";
        }
    }


}
